<template>
    <el-dialog
            :title="!dataForm.id ? '新增' : '修改'"
            :close-on-click-modal="false"
            :visible.sync="visible">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px">
                            <el-form-item label="主键ID" prop="id">
                        <el-input v-model.number="dataForm.id" placeholder="主键ID"></el-input>
                </el-form-item>
                <el-form-item label="监测时间" prop="monitorTime">
                        <el-date-picker
                                v-model="dataForm.monitorTime"
                                type="datetime"
                                placeholder="监测时间">
                        </el-date-picker>
                </el-form-item>
                <el-form-item label="运行工况（正常、异常等）" prop="operationStatus">
                        <el-input v-model="dataForm.operationStatus" placeholder="运行工况（正常、异常等）"></el-input>
                </el-form-item>
                <el-form-item label="设备状态（正常、故障等）" prop="equipmentStatus">
                        <el-input v-model="dataForm.equipmentStatus" placeholder="设备状态（正常、故障等）"></el-input>
                </el-form-item>
                <el-form-item label="指标数据（如设备利用率等）" prop="performanceIndicator">
                        <el-input v-model="dataForm.performanceIndicator" placeholder="指标数据（如设备利用率等）"></el-input>
                </el-form-item>
                <el-form-item label="业务管理信息（描述）" prop="businessManagement">
                        <el-input v-model="dataForm.businessManagement" placeholder="业务管理信息（描述）"></el-input>
                </el-form-item>
                <el-form-item label="发展趋势研判（文本描述）" prop="trendAnalysis">
                        <el-input v-model="dataForm.trendAnalysis" placeholder="发展趋势研判（文本描述）"></el-input>
                </el-form-item>
                <el-form-item label="隐患环节定位（文本描述）" prop="hiddenDangerLocation">
                        <el-input v-model="dataForm.hiddenDangerLocation" placeholder="隐患环节定位（文本描述）"></el-input>
                </el-form-item>
                <el-form-item label="运行方式优化调整措施（文本描述）" prop="optimizationMeasures">
                        <el-input v-model="dataForm.optimizationMeasures" placeholder="运行方式优化调整措施（文本描述）"></el-input>
                </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: null,
            monitorTime: null,
            operationStatus: null,
            equipmentStatus: null,
            performanceIndicator: null,
            businessManagement: null,
            trendAnalysis: null,
            hiddenDangerLocation: null,
            optimizationMeasures: null
          },
          dataRule: {
            id: [
                        { required: true, message: '主键ID不能为空', trigger: 'blur' }
            ],
            monitorTime: [
                        { required: true, message: '监测时间不能为空', trigger: 'blur' }
            ],
            operationStatus: [
                        { required: true, message: '运行工况（正常、异常等）不能为空', trigger: 'blur' }
            ],
            equipmentStatus: [
                        { required: true, message: '设备状态（正常、故障等）不能为空', trigger: 'blur' }
            ],
            performanceIndicator: [
                        { required: true, message: '指标数据（如设备利用率等）不能为空', trigger: 'blur' }
            ],
            businessManagement: [
                        { required: true, message: '业务管理信息（描述）不能为空', trigger: 'blur' }
            ],
            trendAnalysis: [
                        { required: true, message: '发展趋势研判（文本描述）不能为空', trigger: 'blur' }
            ],
            hiddenDangerLocation: [
                        { required: true, message: '隐患环节定位（文本描述）不能为空', trigger: 'blur' }
            ],
            optimizationMeasures: [
                        { required: true, message: '运行方式优化调整措施（文本描述）不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      methods: {
        init (id) {
          this.dataForm.id = id || 0
          this.visible = true
          this.$nextTick(() => {
            this.$refs['dataForm'].resetFields()
            this.dataForm.id = id || 0
            if (this.dataForm.id) {
              this.$http({
                url: this.$http.adornUrl(`/app/distribution_network_management/info/${this.dataForm.id}`),
                method: 'get',
                params: this.$http.adornParams()
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.dataForm = data.appdistributionnetworkmanagement
                }
              })
            }
          })
        },
            // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              this.$http({
                url: this.$http.adornUrl(`/app/distribution_network_management/${!this.dataForm.id ? 'save' : 'update'}`),
                method: 'post',
                data: this.$http.adornData(this.dataForm)
              }).then(({data}) => {
                if (data && data.code === 0) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.msg)
                }
              })
            }
          })
        }
      }
    }
</script>